import re

str="I study python3.7 for spider"

print("-----------match-----------")
m1=re.match(r"I",str)
m2=re.match(r"\w",str)
m3=re.match(r"\D",str)
m4=re.match(r"i",str,re.I)
m5=re.match(r"\S",str)
# m6=re.match("study",str)#匹配不到，因为”study“是从头开始找
m7=re.match(r".",str)
print(m1.group())
print(m2.group())
print(m3.group())
print(m4.group())
print(m5.group())
# print(m6.group())
print(m7.group())
print("-----------search-----------")
s1=re.search(r'study',str)
s2=re.search(r's\w+',str)
s3=re.search(r'p\w+.\d',str)
print(s1.group())
print(s2.group())
print(s3.group())
print("-----------findall-----------")
f1=re.findall(r'y',str)
print(f1)
print("-----------test-----------")
str2='<div><a herf="http://www.baidu.com">百度一下</a></div>'
t1=re.findall('[\u4e00-\u9fa5]\w+',str2)
t2=re.findall('<a herf="http://www.baidu.com">(.+)</a>',str2)
t3=re.findall('herf="(.+)">',str2)
print(t1)
print(t2)
print(t3)
print("-----------sub-----------")
su1=re.sub(r'<div>(.+)</div>',r'<span>\1</span>',str2)
print(su1)



















